package rozetka.pageObjects;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

public class LoginForm {

	WebDriver driver;
	private static final By buttonForRegistration = By
			.xpath("//*[starts-with(@id, 'user-popup-parent')]/div/div/div/form/div[5]/a");
	private static final By loginButton = By.className("auth-f-submit");
	private static final By userCabinet = By
			.xpath("//*[@id='user_menu']/div[2]/a");
	private static final By menuForEntrance = By
			.xpath("//*[starts-with(@id, 'user-popup-parent')]/div/div/div/form/div[5]/a");

	public LoginForm(WebDriver webDriver) {
		driver = webDriver;
	}

	public RegisterDataInputForm openRegistrationForm() {
		driver.findElement(buttonForRegistration).click();
		return new RegisterDataInputForm(driver);
	}

	public void fillEmailInput(String email) {
		driver.findElement(By.name("login")).sendKeys(email);
	}

	public void fillPassword(String passw) {
		driver.findElement(By.name("password")).sendKeys(passw);
	}

	public void login() {
		driver.findElement(loginButton).submit();
	}

	public WebElement findLogedUser() {
		return driver.findElement(userCabinet);
	}

	public WebElement findNotLogedUser() {
		return driver.findElement(menuForEntrance);
	}
}
